#include "TestEffect.h"
#include "GameApplication.h"
#include "CombatComponent.h"
#include "CombatResponse.h"

const HashedString HealthCondition::type("Permanent");

HealthCondition::HealthCondition( Entity* parent, Combat::Combatant* owner ) : Combat::IEffect(owner), m_parent(parent)
{
}

const HashedString& HealthCondition::Type()
{
	return type;
}

void HealthCondition::OnPostDefend( Combat::Response& response )
{
	Subject<int>& health = m_owner->Health();
	float totalDamage = response.physicalDamage + response.specialDamage + response.trueDamage;

	if (health.getObject() - totalDamage <= 0)
	{
		Game.RemoveController(m_parent);
		Game.RemoveEntityFromGroups(m_parent);
		Game.RemoveEntity(m_parent);
	}
}